import Reflux from "reflux";
import {Message} from "@biz/Components";
import GUtils from "@/utils";
import { useNavigate } from 'react-router-dom'
export default class Store extends Reflux.Store {
    constructor(props, action) {
        super(props);
        this.state = this.getInitialState();
        this.listenables = action;
        this.props = props;
        this.action = action;
    }

    getInitialState() {
        return {};
    }

    onLogin(){
        this.setState({loading:true})
    }
    onLoginCompleted(res) {
        this.setState({loading:false})
        if (res.success) {
            Message.success("登录成功");
            GUtils.loginSuccess(res.vo);

            let redirect_url = GUtils.getQueryString('redirect_url');

            if (redirect_url) {
                redirect_url = decodeURIComponent(redirect_url);
                window.RouterGo(redirect_url);
            } else {
                window.RouterGo(window.CONFIG.PAGE_HOME);
            }
        } else {
            Message.error(res.errMsg);
            this.setState({errMsg: res.errMsg});
        }
    }
}